
mid=(2+1)>>1
print(mid)
m,n,r=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

def bianrySearch(arr,target):
    low=0
    high=len(arr)-1
    while low<=high:
        mid=(low+high)//2
        midVal=arr[mid]
        if midVal>target:
            high=mid-1
        elif midVal<target:
            low=mid+1
        else:
            return mid
    return -low-1

def getResult():
    for ai in a:
        j=bianrySearch(b,ai)
        if j>=0:
            print(f"{ai} {b[j]}")
        else:
            insertIdx=-j-1
            if b[insertIdx]-ai<=r:
                print(f"{ai} {b[insertIdx]}")

getResult()